package cn.itcast.tlias.com.tliaswork.mapper;

import cn.itcast.tlias.com.tliaswork.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    /**
     * 获取用户数量
     * @return
     */
    @Select("SELECT count(*) FROM emp")
    Long searchCount();

    /**
     * 分页查询
     * @param start
     * @param pageSize
     * @return
     */
    @Select("SELECT * from emp LIMIT #{start},#{pageSize}")
    List<Emp> searchLimit(@Param("start") Integer start, @Param("pageSize") Integer pageSize);


    /**
     * 获取所有用户
     *
     * @return
     */
    @Select("SELECT * FROM emp")
    List<Emp> list();

    /**
     *  根据条件查询数据
     * @param name
     * @param gender
     * @param begin
     * @param end
     * @return
     */
    List<Emp> listCondition(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);


    /**
     *  批量删除
     * @param ids
     */
    void delete(@Param("ids") List<Integer> ids);

//      private String username; //用户名
//    private String password; //密码
//    private String name; //姓名
//    private Short gender; //性别,1 男, 2 女
//    private String image; //图像Url
//    private Short job; //职位,说明:1班主任,2讲师,3学工主管,4教研主管,5咨询师
//    private LocalDate entrydate; //入职日期
//    private Integer deptId; //部门ID
//    private LocalDateTime createTime; //创建时间
//    private LocalDateTime updateTime

    @Insert("INSERT INTO emp (username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time) VALUES" +
            "(#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("SELECT * FROM emp WHERE id = #{id}")
    Emp query(Integer id);

    void updata(Emp emp);

    @Select("SELECT * FROM emp WHERE username = #{username} AND password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);

    @Delete("DELETE FROM emp WHERE dept_id = #{deptId}")
    void deleteByDeptId(int deptId);
}
